package com.leyou.controller;

import java.util.Arrays;
import java.util.Map;

import com.leyou.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.leyou.entity.CategoryBrandEntity;
import com.leyou.service.CategoryBrandService;



/**
 * 商品分类和品牌的中间表，两者是多对多关系
 *
 * @author Daifeng
 * @email 2661184062@qq.com
 * @date 2020-12-25 16:44:48
 */
@RestController
@RequestMapping("leyou/categorybrand")
public class CategoryBrandController {


    @Autowired
    private CategoryBrandService categoryBrandService;

    /**
     * 信息
     */
    @RequestMapping("/info/{categoryId}")
    public R info(@PathVariable("categoryId") Long categoryId){
		CategoryBrandEntity categoryBrand = categoryBrandService.getById(categoryId);

        return R.ok().put("categoryBrand", categoryBrand);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CategoryBrandEntity categoryBrand){
		categoryBrandService.save(categoryBrand);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CategoryBrandEntity categoryBrand){
		categoryBrandService.updateById(categoryBrand);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] categoryIds){
		categoryBrandService.removeByIds(Arrays.asList(categoryIds));

        return R.ok();
    }

}
